<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
    <title>房源推荐信息</title>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
    <style type="text/css">
        .layui-table-cell {
            height: 100%;
            max-width: 100%;
        }
    </style>
</head>
<body>



<div id="test1" class="demo-transfer"></div>





<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">


    layui.use(['transfer', 'layer', 'util'], function () {
        var transfer = layui.transfer;
        var layer = layui.layer;
        var util = layui.util;

        getRecommedList();

        var data1 = [];
        var data2 = [];

        function getRecommedList() {
            $.ajax({
                url: 'house-room-recommend/list',
                type: 'get',
                dataType: 'json',
                success : function (result) {
                    if (result.code == 200) {

                        data1 = result.data.leftData;
                        data2 = result.data.rightData;

                        transfer.reload('demo1', {
                            data: data1
                            ,value: data2
                        });
                    }
                }
            });
        }

        //显示搜索框
        transfer.render({
            elem: '#test1'
            ,data: data1
            ,value: data2
            ,title: ['普通房源', '推荐房源']
            ,showSearch: true
            ,width: 610
            ,height: 550
            ,onchange: function(data, index){
                updateRecommend(data, index);//如果数据来自左边，index 为 0，否则为 1
            }
            ,id: 'demo1'
        })

        function updateRecommend(data, index) {
            $.ajax({
                url: 'house-room-recommend/update',
                data: {
                    json : JSON.stringify(data),
                    index : index
                },
                type: 'put',
                dataType: 'json',
                success: function (result) {
                    if (result.code == 200) {
                        if (index == 0) {
                            layer.msg("设置推荐房源成功！",{icon:'1',title:'提示',closeBtn :'1'});
                        }else {
                            layer.msg("取消推荐房源成功！",{icon:'1',title:'提示',closeBtn :'1'});
                        }
                    }
                }
            });
        }



    });
</script>


</body>
</html>